package com.gitee.dolt.boot.controller;

import com.gitee.dolt.boot.service.SuperService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;

/**
 * 简单的实现了BaseController，为了获取注入 Service 和 实体类型
 *
 * @author LYH
 */
public abstract class SuperSimpleController<Entity, Service extends SuperService<Entity>> implements BaseController<Entity> {

    protected Class<Entity> entityClass = null;

    @Autowired
    protected Service baseService;

    @Override
    public Class<Entity> getEntityClass() {
        if (entityClass == null) {
            this.entityClass = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        }
        return this.entityClass;
    }

    @Override
    public Service getBaseService() {
        return baseService;
    }


}
